<template>
  <div id="new">
    <f7-page v-if="$f7route.context">
      <f7-navbar title="法律法规" back-link></f7-navbar>
      <f7-list bg-color="white" class="no-margin">
        <div v-if="list.length === 0" class="text-align-center text-color-gray no-data-div">暂无法律法规</div>
        <f7-list-item link color="black" @click="opennew(n)" v-for="n in list" :key="n.id">{{n.name}}</f7-list-item>
      </f7-list>
    </f7-page>
    <f7-list v-else bg-color="white" class="no-margin">
      <div v-if="list.length === 0" class="text-align-center text-color-gray no-data-div">暂无公示</div>
      <f7-list-item link color="black" @click="opennew(n)" v-for="n in list" :key="n.id">{{n.name}}</f7-list-item>
    </f7-list>
  </div>
</template>
<script>
import { f7List, f7ListItem, f7Page, f7Navbar } from 'framework7-vue'
export default {
  components: {
    f7List,
    f7ListItem,
    f7Page,
    f7Navbar
  },
  data() {
    return {
      list: []
    }
  },
  async created() {
    this.$root.$off('destroy-index').$on('destroy-index', () => {
      this.$destroy()
    })
    const { data } = await this.request('/getnews', { type: this.$f7route.context || 0 })
    this.list = data
  },
  methods: {
    opennew({ id, url }) {
      // 1法律法规，0新闻
      this.$f7.views.main.router.navigate('/browse', { context: url || `${window.baseUrl}/getnew?id=${id}`, type: this.$f7route.context || 0 })
    }
  }
}
</script>